package icu.lookyousmileface.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @author shenj
 * @title: ServiceTerminal
 * @projectName NettyPro
 * @date 2020/12/4 14:29
 */
public class ServiceTerminal {
    public static void main(String[] args) throws Exception {

        EventLoopGroup mainLoop = new NioEventLoopGroup();
        EventLoopGroup workerLoop = new NioEventLoopGroup();

        try{
            ServerBootstrap serverStartApplicationConfiguration = new ServerBootstrap();

            serverStartApplicationConfiguration.group(mainLoop, workerLoop)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ServerChannelInitializer());

            System.out.println("Server is ready....");

            ChannelFuture channelFuture = serverStartApplicationConfiguration.bind(7744).sync();

            channelFuture.channel().closeFuture().sync();
        }finally {
            mainLoop.shutdownGracefully();
            workerLoop.shutdownGracefully();
        }
    }
}
